package ac.zlf.springmybatis.init;

import ac.zlf.springmybatis.init.entity.Demo;
import ac.zlf.springmybatis.init.entity.Menu;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;

import java.util.Date;

/**
 * Created by Administrator on 2017/4/16 0016.
 */
public class InitMenu {

    @Test
    public void testCreeateTable(){
        Configuration config = new AnnotationConfiguration().configure();
        SchemaExport export = new SchemaExport(config);
        export.create(true, true);
    }
    @Test
    public void initData(){
        Session session =HibernateUtil.getSession();

        Transaction transaction = session.beginTransaction();

        Menu menu = new Menu();
        menu.setMenuName("系统");
        menu.setGarde(1);
        session.save(menu);
        Menu menu1 = new Menu("设置","",1,2);
        session.save(menu1);
        Menu menu2 = new Menu("设置","",2,3);
        session.save(menu2);
        transaction.commit();
//        session.close();
    }

}
